<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 2, 4, 5];
            console.log(arr.indexOf(2)); // 1
            console.log(arr.indexOf(2, 2)); // 2 从索引2开始查
            console.log(arr.indexOf(2, -3)); // 2 从-3（即索引2开始）
            console.log(Array.prototype);
            Array.prototype.myIndexof = function (value, start = 0) {
                if (start < 0) start = this.length + start;
                for (; start < this.length; start++) {
                    if (this[start] == value) {
                        return start;
                    }
                }
                return -1;
            };
            console.log(arr.myIndexof(2)); // 1
            console.log(arr.myIndexof(2, 2)); // 2 从索引2开始查
            console.log(arr.myIndexof(2, -3)); // 2 从-3（即索引2开始）
        </script>
    </body>
</html>
